function varargout = batch_params(varargin)
% $Id: batch_params.m 320 2005-05-05 20:07:09Z odellj $
% BATCH_PARAMS Application M-file for batch_params.fig
%    FIG = BATCH_PARAMS launch batch_params GUI.
%    BATCH_PARAMS('callback_name', ...) invoke the named callback.

% Last Modified by GUIDE v2.5 27-May-2003 12:59:58
% $Log: batch_params.m,v $
% Revision 1.4  2005/02/16 22:54:07  odellj
% Fixed the line to correctly parse session and configuration input.
%
% Revision 1.3  2005/02/09 21:27:47  odellj
% Configurations, Sessions, and Subject List fields now prune out any lines that are extra (trailing \n from hitting enter).  This will prevent miscounting for loop iterations.
%
% Revision 1.2  2004/03/31 22:41:18  odellj
% Getting ready for the subj list bugfix.
%
% Revision 1.1.1.1  2004/02/18 20:09:49  odellj
% initial import into CVS
%
% Revision 1.2  2004/02/05 20:21:16  odellj
% Added Id and Log tags.
%

global hdr

if nargin == 0  % LAUNCH GUI

	fig = openfig(mfilename,'reuse');

	% Use system color scheme for figure:
	set(fig,'Color',get(0,'defaultUicontrolBackgroundColor'));

	% Generate a structure of handles to pass to callbacks, and store it. 
	handles = guihandles(fig);
    %NewVal=num2str(hdr.n_srcs);
    set(handles.Subj_list,'String',hdr.subj_list);
    set(handles.Configs,'String',hdr.config);
    set(handles.Session,'String',hdr.SS);
	guidata(fig, handles);

	if nargout > 0
		varargout{1} = fig;
	end

elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK

	try
		if (nargout)
			[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
		else
			feval(varargin{:}); % FEVAL switchyard
		end
	catch
		disp(lasterr);
	end

end

% --------------------------------------------------------------------
function varargout = Subj_list_Callback(h, eventdata, handles, varargin)
global hdr

% remove carriage return.
temp = get(h,'String');
acc = temp(1,:);
for i = 1:size(temp,1)
    if ~strcmp(deblank(temp(i,:)),'')
        acc(size(acc,1)+1,:) = temp(i,:);
    end
end
acc = acc(2:size(acc,1),:);

hdr.subj_list=str2num(acc);
hdr.n_subjs=max(size(hdr.subj_list));


% --------------------------------------------------------------------
function varargout = Configs_Callback(h, eventdata, handles, varargin)
global hdr

temp = get(h,'String');
acc = temp(1,:);
for i = 1:size(temp,1)
    if ~strcmp(deblank(temp(i,:)),'')
        acc(size(acc,1)+1,:) = temp(i,:);
    end
end
acc = acc(2:size(acc,1),:);

hdr.config = acc;
hdr.n_configs=size(hdr.config,1);

% --------------------------------------------------------------------
function varargout = Session_Callback(h, eventdata, handles, varargin)
global hdr

temp = get(h,'String');
acc = temp(1,:);
for i = 1:size(temp,1)
    if ~strcmp(deblank(temp(i,:)),'')
        acc(size(acc,1)+1,:) = temp(i,:);
    end
end
acc = acc(2:size(acc,1),:);

hdr.SS = acc;

% --------------------------------------------------------------------
function varargout = Done_Callback(h, eventdata, handles, varargin)
global hdr

close

% --- Executes during object creation, after setting all properties.
function factors_CreateFcn(hObject, eventdata, handles)

% if ispc
%     set(hObject,'BackgroundColor','white');
% else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
% end

function factors_Callback(hObject, eventdata, handles)
global hdr

hdr.factors=get(h,'String');
hdr.n_factors=size(hdr.factors,1);
